//
//  KKPersonalArticleVC.m
//  DoMi
//
//  Created by 康凯 on 2016/11/25.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKPersonalArticleVC.h"
#import "KKComHttp.h"
#import "KKArticalCell.h"
#import "KKArticleListM.h"
#import "KKArticleDetailVC.h"
@interface KKPersonalArticleVC ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic)NSArray *articleDatas;
@end

@implementation KKPersonalArticleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    // Do any additional setup after loading the view from its nib.
    [self.tableView registerNib:[UINib nibWithNibName:@"KKArticalCell" bundle:nil] forCellReuseIdentifier:@"KKArticalCell"];
    
    [self getExpertArticle];
}

#pragma mark tableview代理
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    KKArticalCell *article=(KKArticalCell *)cell;
    [article initData:self.articleDatas[indexPath.row]];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.articleDatas.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:@"KKArticalCell"];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 101;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 8;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    KKArticleListM *data= self.articleDatas[indexPath.row];
    KKArticleDetailVC *detail=[[KKArticleDetailVC alloc] init];
    detail.docId=data.articleid;
    [self.navigationController pushViewController:detail animated:YES];
}

#pragma mark 接口--专家文章
-(void)getExpertArticle{
    [self showDialog];
    [KKComHttp getExpertArticle:self.expertId success:^(id data) {
        self.articleDatas=data;
        [self.tableView reloadData];
        [self dismissDialog];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
@end
